<template>
	<view class="test-page">
		<view>{{ JSON.stringify(test) }}</view>
		<web-view v-if="mapshow" id="web-view-2" :src="src" @message="handleMessage"></web-view>
	</view>
</template>

<script>
	export default {
		onLoad(e) {
			this.webViewContext = my.createWebViewContext('web-view-2');
			console.log(e.origin,e.destination)
			this.src = this.src + '?origin='+ e.origin +'&destination=' +e.destination
			// 向webview发送信息
			setTimeout(() => {
				const path = [[119.985074, 30.518515], [119.985782, 30.518658], [119.987128, 30.517909], [119.985696, 30.516426], [119.98516, 30.516865]]
				this.webViewContext.postMessage({ path });
			}, 500)
		},
		data() {
			return {
				// src:'http://192.168.137.1:5500/index.html',
				src: 'https://zhatu.deqing.gov.cn/polygonDraw/index.html',
				webViewContext: null,
				mapshow: true,
				test: {},
			}
		},
		methods: {
			// webview向app发送信息
			handleMessage(evt) {
				console.log('收到webview信息', evt.detail)
				this.mapshow = false
				this.test = evt.detail.path
				this.$store.state.path = evt.detail.path
				uni.showToast({
					title: '交警路线选择完成',
					duration: 99
				})
				uni.navigateBack()
			},
		},
	}
</script>

<style lang="scss" scoped>
	.test-page {
		background-color: yellow;

		#web-view-1 {
			position: absolute;
			top: 100px;
			left: 0;
		}
	}
</style>
